package com.wolfcode.appointment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wolfcode.appointment.domain.vo.BusServiceItemAuditVo;
import com.wolfcode.appointment.domain.vo.BusServiceItemVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.appointment.domain.BusServiceItem;
import com.wolfcode.appointment.service.IBusServiceitemService;
import com.wolfcode.common.utils.poi.ExcelUtil;
import com.wolfcode.common.core.page.TableDataInfo;

/**
 * 服务项Controller
 *
 * @author wolfcode
 * @date 2022-11-23
 */
@RestController
@RequestMapping("/appointment/serviceitem")
public class BusServiceitemController extends BaseController {
    @Autowired
    private IBusServiceitemService busServiceitemService;

    /**
     * 查询服务项列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusServiceItem busServiceitem) {
        startPage();
        List<BusServiceItem> list = busServiceitemService.selectBusServiceitemList(busServiceitem);
        return getDataTable(list);
    }

    /**
     * 导出服务项列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:export')")
    @Log(title = "服务项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusServiceItem busServiceitem) {
        List<BusServiceItem> list = busServiceitemService.selectBusServiceitemList(busServiceitem);
        ExcelUtil<BusServiceItem> util = new ExcelUtil<BusServiceItem>(BusServiceItem.class);
        util.exportExcel(response, list, "服务项数据");
    }

    /**
     * 获取服务项详细信息
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(busServiceitemService.selectBusServiceitemById(id));
    }

    /**
     * 新增服务项
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:add')")
    @Log(title = "服务项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusServiceItemVo busServiceItemVo) {
        return toAjax(busServiceitemService.insertBusServiceitem(busServiceItemVo));
    }

    /**
     * 修改服务项
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:edit')")
    @Log(title = "服务项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusServiceItemVo busServiceItemVo) {
        return toAjax(busServiceitemService.updateBusServiceitem(busServiceItemVo));
    }

    /**
     * 删除服务项
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:remove')")
    @Log(title = "服务项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(busServiceitemService.deleteBusServiceitemByIds(ids));
    }


    /**
     * 上架
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:saleOn')")
    @Log(title = "服务项", businessType = BusinessType.UPDATE)
    @PutMapping("/saleOn/{id}")
    public void saleOn(@PathVariable Long id) {
        busServiceitemService.saleOn(id);
    }

    /**
     * 下架
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:saleOn')")
    @Log(title = "服务项", businessType = BusinessType.UPDATE)
    @PutMapping("/saleOff/{id}")
    public void saleOff(@PathVariable Long id) {
        busServiceitemService.saleOff(id);
    }

    /**
     * 获取审核页面信息
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:audit')")
    @GetMapping(value = "/audit/{id}")
    public AjaxResult auditInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(busServiceitemService.auditInfo(id));
    }

    /**
     * 提交审核
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceitem:startAudit')")
    @PutMapping("/audit")
    public AjaxResult startAudit(@RequestBody BusServiceItemAuditVo auditVo) {
        busServiceitemService.startAudit(auditVo);
        return AjaxResult.success();
    }

}
